$(function() {
	var url = 'http://ittalentsapi.bashibozuk.eu/game?X-GameID=102&expand=user&page=1&per-page=10&sortField=score&sortDirection=DESC';;
	  
	$.ajax(url, {
		method: 'GET',
		crossDomain: true,
		dataType: 'json',
		
		success: function(data) {
                        console.log(data.id)
                        var n = parseInt(arguments[2].getAllResponseHeaders()[131]+arguments[2].getAllResponseHeaders()[132]);
			var string = '';
			for(var i=1;i<=10;i++) {
				
				string+='<div class="playersRow"><span>'+i+'</span><span>'+data[i-1].user.username+'</span><span >'+data[i-1].score+'</span></div>';
			}
			$('#crTable').html(string);	
			string = '';
			for(var i=1;i<=n/10+1;i++) {
				string+="<a class='numbering' id='"+i+"' href='#'>"+i+"</a>";
			}
			$('#menu_hs').html(string);
			$('.numbering').click(function(event) {
                            
				event.preventDefault();
				var that=this;
                                
				url = 'http://ittalentsapi.bashibozuk.eu/game?X-GameID=102&expand=user&page='+this.id+'&per-page=10&sortField=score&sortDirection=DESC';
				$.ajax(url, {
					method: 'GET',
					crossDomain : true,
					success: function(data) {
						var string = '';
						for(var i=0;i<data.length;i++) {
							string+='<div class="playersRow"><span>'+((i+1)+10*(that.id-1))+'</span><span>'+data[i].user.username+'</span><span>'+data[i].score+'</span></div>';
						}
						$('#crTable').html(string);
					}});
			});
			
		}
	});
	
        
});
